package com.hnzq.cloud.controller;


import com.hnzq.cloud.dto.FreImgDto;
import com.hnzq.cloud.model.Result;
import com.hnzq.cloud.param.AddFreImgsParam;
import com.hnzq.cloud.param.DeleteImgsParam;
import com.hnzq.cloud.service.FreImgService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jams
 * @since 2022-02-06
 */
@RestController
@RequestMapping("freImg")
public class FreImgController {

    @Resource
    private FreImgService freImgService;

    @GetMapping("findFreGoodsImgs")
    public Result findFreGoodsImgs(@RequestParam("id") Integer id){
        List<FreImgDto> freGoodsImgs = freImgService.findFreGoodsImgs(id);
        return Result.newInstance().setMessage("查询成功").setData(freGoodsImgs);
    }

    @PostMapping("addFreImg")
    public Result addFreImg(@RequestBody AddFreImgsParam addFreImgsParam){
        Boolean bool = freImgService.addFreImg(addFreImgsParam);
        if (bool){
            return Result.newInstance().setMessage("新增成功");
        }else {
            return Result.newInstance().setMessage("新增失败").setCode(144);
        }
    }

    @DeleteMapping("deleteFreImg")
    public Result deleteFreImg(@RequestBody DeleteImgsParam deleteImgsParam){
        Boolean bool = freImgService.deleteFreImg(deleteImgsParam);
        if (bool){
            return Result.newInstance().setMessage("删除成功");
        }else {
            return Result.newInstance().setMessage("删除失败").setCode(144);
        }
    }

}

